export default {

	enterReadDetailInfoClick() {
		
		
		let readInfo = uni.getStorageSync("readProcessData" + this.bookInfo.bookCode);
		let chapterIndex = 0;
		if(readInfo == null || readInfo == ""){
			chapterIndex = 1
		}else{
			chapterIndex =readInfo.readProcessData.detail.index
		}
		
		uni.navigateTo({
			url: '../readDetail/aNovelDirectory/aNovelDirectoryView?bookCode=' + this.bookInfo.bookCode +
				"&chapterIndex=" + chapterIndex+"&pageType=bookDetail"
		})

	},
	// 处理分享功能
	handleShare() {
		uni.showToast({
			title: this.$t('bookInfoDetail.shareDeveloping'),
			icon: 'none'
		});
	},
	// 处理举报功能
	handleReport() {
		uni.showToast({
			title: this.$t('bookInfoDetail.reportDeveloping'),
			icon: 'none'
		});
	},
	// 处理推荐功能
	handleRecommend() {
		uni.showToast({
			title: this.$t('bookInfoDetail.recommendDeveloping'),
			icon: 'none'
		});
	},
	startReadBookInfo() {

		var bookInfoStr = JSON.stringify(this.bookInfo);
		uni.navigateTo({
			url: '/pages/baseBusiness/readDetail/readDetailView?bookInfo=' + bookInfoStr
		})

	},
	enterBookInfoDetail(e){
		var bookInfoStr = JSON.stringify(e);
		uni.navigateTo({
			url: '/pages/baseBusiness/bookInfoDetail/bookInfoDetailView?bookInfo=' + bookInfoStr
		})
	},
	getSimilarBook() {
		
		this.getBookDataRandomly();

	},
	collectionBookInfoClick() {
		this.bookInfo.isCollection = true;
		var dataItems = [this.bookInfo];
		this.$sqlDBConfig.insertCollectionTableTableData(dataItems);
	},
	
	removeBookInfoClick() {
		let that = this;
		this.$sqlDBConfig.deleteCollectionTableTableData(that.bookInfo,(type, res) => {
			console.log(type,res);
			if(type == "success"){
				this.bookInfo.isCollection = false;
			}else{
				uni.showToast({
					title: this.$t('bookInfoDetail.removeBookError'),
					icon: 'none'
				});
			}
		});
	},

	//  获取分类数据列表
	async getListOfClassifiedData() {

		var that = this;
		var localHttp = that.$http_url.getHttpUrl();
		var param = {
			info: {
				pageNum: 1,
				pageSize: 300
			},
			code: that.bookInfo.bookCode
		}
		
		var dataRes = await this.$sqlDBConfig.selectCollectionTableData2();
		that.$api.getCateItemDetail(param).then(res => {
			if (res.statusCode == 200) {
				that.bookList = res.data.rows;
				that.bookList.forEach(function(item, index) {
				      item.bookIconUrl = localHttp+"/images/"+item.bookCode+"/"+item.bookPic;
					  item.isCollection = false
					  dataRes.forEach(function(item1, index1) {
							  if(item1.bookcode == item.bookCode){
								   item.isCollection = true
							  }
					  })
				})
				if(that.bookList.length>0){
					that.getBookDataRandomly();
				}
			} 
		}).catch(error => {

		})

	},


	//  获取随机数据列表
	getBookDataRandomly() {
		
		var that = this;

		var randomNums = [];
		while (randomNums.length < 3) {
			let num = parseInt(Math.random() * this.bookList.length)
			// parseInt取正，小数点后面的数字全部抹掉
			// Math.random() 0-1的随机数
			if (randomNums.indexOf(num) == -1) {
				// this.arr.indexOf(num)若等于-1则证明arr这个数组里没有num这个随机数，因此可以放进这个数组里
				randomNums.push(num)
			}
		}


		that.randomBooks = [];
		randomNums.forEach((item) => {
		    that.randomBooks.push(that.bookList[item]);
		})
		// console.log(that.randomBooks,"hahahahahahahaahh")
		
		
		// randomBooks

	}


}
